<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-06-25
 * Time: 15:00
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IDepartment;
use App\Http\Requests\Admin\DepartmentInputDTO;
use App\Util\LayUiVo;
use App\Util\ResultsVo;
use Illuminate\Support\Facades\Lang;

class DepartmentController extends Controller
{
    protected $departmentService;

    public function __construct(IDepartment $departmentService)
    {
        $this->departmentService = $departmentService;
    }
    public function store(DepartmentInputDTO $inputDTO){
        $this->departmentService->store($inputDTO);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function page(){
        $data = $this->departmentService->getAll();
        return response()->json(new LayUiVo(['data'=>$data,'message'=>Lang::get('response.success')]));
    }

    public function delete($id){
        $this->departmentService->delete($id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }

    public function update(DepartmentInputDTO $inputDTO,$id) {
        $this->departmentService->update($inputDTO,$id);
        return response()->json(new ResultsVo(['message'=>Lang::get('response.success')]));
    }
}